package com.fcscs.ecms.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fcscs.cservice.ws.schema.awuservice.AwuCall;
import com.fcscs.ecms.dao.ECMSGuestRequestAwuDao;
import com.fcscs.ecms.dao.ECMSGuestRequestDao;
import com.fcscs.ecms.domain.GuestRequest;
import com.fcscs.ecms.domain.GuestRequestAwu;
import com.fcscs.ecms.service.ECMSAwuManager;

/**
 * @author pvttinh
 * 
 */

@Service("ecmsAwuManager")
public class ECMSAwuManagerImpl implements ECMSAwuManager {

	@Autowired
	private ECMSGuestRequestDao ecmsGuestRequestDao;
	@Autowired
	private ECMSGuestRequestAwuDao ecmsGuestRequestAwuDao;

	@Override
	public List<AwuCall> getAwuList(long orgId, long propertyId, long guestProfileId) throws Exception {
		// TODO Auto-generated method stub
		List<AwuCall> list = new ArrayList<AwuCall>();
		try{
			List<GuestRequest> grList = this.ecmsGuestRequestDao.findListBy((int)orgId, (int)propertyId, (int)guestProfileId, "AWU");
			for(GuestRequest gr : grList){
				GuestRequestAwu gra = this.ecmsGuestRequestAwuDao.get(gr.getId());
				
				AwuCall ac = new AwuCall();
				ac.setGuestRequestId(gra.getGuestRequestId());
				ac.setAwuDateTime(gra.getAwuDateTime());
				ac.setOccurrence(gra.getOccurence());
				
				list.add(ac);
			}
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("Awu.MANAGER.getAwuList() - " + e.getMessage());
		}
		
		return list;
	}

	@Override
	public AwuCall setAwuCall(AwuCall awuCall) throws Exception {
		// TODO Auto-generated method stub
		try{
			GuestRequestAwu gra = this.ecmsGuestRequestAwuDao.get((int)awuCall.getGuestRequestId());
			
			gra.setAwuDateTime(awuCall.getAwuDateTime());
			gra.setOccurence((int)awuCall.getOccurrence());
			
			this.ecmsGuestRequestAwuDao.update(gra);
		}catch (Exception e) {
			// TODO: handle exception
			throw new Exception("Awu.MANAGER.setAwuCall() - " + e.getMessage());
		}
		
		return awuCall;
	}
}
